package com.example.common;

import com.example.exception.SelfExceptionEnum;
import lombok.Data;

@Data
public class Rust<T> {
    //设置编码，0表示失败，1表示成功,1000+表示异常
    private int code;
    //设置返回字符串
    private String msg;
    //数据
    private T data;

    public static <T> Rust<T> success(T object){
        Rust<T> r = new Rust<>();
        r.code = 1;
        r.data = object;
        return r;
    }

    public static <T> Rust<T> error(String msg){
        Rust<T> r = new Rust<>();
        r.code = 0;
        r.msg = msg;
        return r;
    }

    //异常处理
    public static <T> Rust<T> error(SelfExceptionEnum selfExceptionEnum){
        Rust<T> r = new Rust<>();
        r.code = selfExceptionEnum.getCode();
        r.msg = selfExceptionEnum.getMsg();
        return r;
    }
}
